#pragma once

#include <iostream>
#include <cstdio>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <cstdlib>
#include <cassert>
#include <cstring>
using namespace std;

#define PATH_NAME "/home/rbc"
#define PROJ_ID 20
#define SIZE 4096
#define FIFO_PATH "./fifo"

class Init
{
public:
    Init()
    {
        umask(0);
        int ret = mkfifo(FIFO_PATH,0666);
        assert(ret != -1);
        (void)ret;
    }
    ~Init()
    {
       int ret = unlink(FIFO_PATH);
       assert(ret != -1);
       (void)ret;
    }
};

//一个告诉我是要读还是要写，我给你返回相应的文件描述符
int OpenFIFO(int flags)
{
    int fd = open(FIFO_PATH,flags);
    assert(fd != -1);
    return fd;
}

//一个等待函数
void Wait(int fd)
{
    cout<<"等待中···"<<"\n";
    uint32_t temp = 0;
    int s = read(fd,&temp,sizeof(uint32_t));
    assert(s == sizeof(uint32_t));
    return;
}
//一个唤醒函数
void Singal(int fd)
{
    cout<<"唤醒中···"<<"\n";
    uint32_t temp = 1;
    int s = write(fd,&temp,sizeof(uint32_t));
    assert(s == sizeof(uint32_t));
    cout<<"唤醒成功"<<"\n";
    return;
}